<!DOCTYPE html>
<html>
	<head>
		<title><?php echo lang('site_title');?></title>
		<meta name="viewport" content="initial-scale=1.0">
		<meta charset="utf-8">

		<link type="text/css" href="<?php echo base_url();?>static/css/google_map.css" />

		<script async defer src="https://maps.googleapis.com/maps/api/js?key=<?php echo $google_ak;?>&callback=googleMap.processor"></script>

	</head>
	<body>
		<h1><?php echo $title; ?></h1>


		<div class="mapContainer" style="height:400px;"></div>

		<script type="text/javascript">

			var googleMap = {};
			googleMap.mapHandle = null;
			googleMap.container = document.getElementsByClassName("mapContainer")[0];
			googleMap.points = {
				init: {lat: -34.397, lng: 150.644},
				geolocation: {lat: -34.397, lng: 150.644},
				
			};
			googleMap.options = {
				init: {
					center: googleMap.points.init,
					zoom: 6
				},
				geolocation: {
					center: googleMap.points.geolocation,
					zoom: 6
				},

			};

			googleMap.processor = function() {
				this.init();
				this.geolocation();
			};

			googleMap.init = function() {
				this.mapHandle = new google.maps.Map(this.container, this.options.init);

				return this;
			};

			googleMap.marker = function() {
				var marker = new google.maps.Marker({
					position: this.points.marker,
					map: this.mapHandle
				});

				return this;
			};

			// Note: This example requires that you consent to location sharing when
			// prompted by your browser. If you see the error "The Geolocation service
			// failed.", it means you probably did not give permission for the browser to
			// locate you.
			googleMap.geolocation = function() {
				var infoWindow = new google.maps.InfoWindow({map: googleMap.mapHandle});

				// Try HTML5 geolocation.
				if (navigator.geolocation) {
					navigator.geolocation.getCurrentPosition(function(){
						var pos = {
							lat: position.coords.latitude,
							lng: position.coords.longitude
						};

						infoWindow.setPosition(pos);
						infoWindow.setContent("Location found.");
						googleMap.mapHandle.setCenter(pos);
					}, function(){
						handleLocationError(true, infoWindow, googleMap.mapHandle.getCenter());
					});
				} else {
					// Browser doesn't support Geolocation
					handleLocationError(false, infoWindow, googleMap.mapHandle.getCenter());
				}

				var handleLocationError = function(browserHasGeolocation, infoWindow, positon){
					infoWindow.setPosition(positon);
					infoWindow.setContent(browserHasGeolocation ? 
						"Error: The Geolocation service failed." : 
						"Error: Your browser doesn't support geolocation.");
				};
			};





		</script>






	</body>
</html>
